<?php

class sysnavmodule_config {
	
	/**
	* Return default config object
	* 
	*/
	function getDefaultConfig(){
		$obj=null;
		return $obj;
	}
	
	function form($object) {
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();

		$form = new form();
		if (!isset($object->id)) {
			$object->sort = 'asc_name';
			$object->remove_body_html=0;
			$object->default_on_admin=0;
			$object->first_link_as_title=0;
			$object->no_search=0;
			$object->item_width=100;
		} else {
			switch ($object->orderhow) {
				case 0: // ascending
					$object->sort = 'asc_'.$object->orderby;
					break;
				case 1: // descending
					$object->sort = 'desc_'.$object->orderby;
					break;
				case 2: // random
					$object->sort = 'random_';
					break;
				case 3: // order specified by arrows
					$object->sort = 'rank_';
					break;
				default:
					$object->sort = 'asc_name';
					break;
			}
			$form->meta('id',$object->id);
		}

		$order_options = array(
			'random_'=>'Randomly',
			'asc_name'=>'Alphabetical By Name',
			'desc_name'=>'Reverse Alphabetical By Name',
			'rank_'=>'By rank order specified',
		);
		$form->register('orderby','Sorting',new dropdowncontrol($object->sort,$order_options));
		$form->register('remove_body_html','Remove HTML on body content&nbsp;',new checkboxcontrol($object->remove_body_html));
		$form->register('default_on_admin','Show Default view on Administrator mode&nbsp;',new checkboxcontrol($object->default_on_admin));
		$form->register('first_link_as_title','First link as title&nbsp;',new checkboxcontrol($object->first_link_as_title));
		// Sep 22, 2011 - trungdt - Add no search
		$form->register('item_width','Image Thumb Width',new textcontrol($object->item_width));
		$form->register('no_search','No Serach Generate&nbsp;',new checkboxcontrol($object->no_search));
		$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
		return $form;
	}

	function update($values,$object) {
		$toks = explode('_',$values['orderby']);
		switch ($toks[0]) {
			case 'rank':
				$object->orderhow = 3;
				break;
			case 'random':
				$object->orderhow = 2;
				break;
			case 'asc':
				$object->orderhow = 0;
				break;
			case 'desc':
				$object->orderhow = 1;
				break;
		}
		
		$object->item_width = intval($values['item_width']);
		
		$object->orderby = $toks[1];
		if (isset($values['remove_body_html'])){
			$object->remove_body_html=1;
		}
		else
		{
			$object->remove_body_html=0;
		}
		
		if (isset($values['default_on_admin'])){
			$object->default_on_admin=1;
		}
		else
		{
			$object->default_on_admin=0;
		}
		
		if (isset($values['first_link_as_title'])){
			$object->first_link_as_title=1;
		}
		else
		{
			$object->first_link_as_title=0;
		}
		
		if (isset($values['no_search'])){
			$object->no_search=1;
		}
		else
		{
			$object->no_search=0;
		}
		
		return $object;
	}
}

?>